package com.lizx.framework.web.smart.framework.core.utils;

import org.apache.log4j.Logger;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @Author: 李宁 William-Li
 * @Description:
 * @Date: Create in 2019/1/18 4:51 PM
 */
public class CodeUtil {
    private static final Logger LOGGER = Logger.getLogger(CodeUtil.class);

    /**
     * url 编码
     * @param source
     * @return
     */
    public static String encodeURL(String source){
        String target;
        try {
            target = URLEncoder.encode(source, "utf-8");
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("url编码失败"+e);
            throw new RuntimeException(e);
        }
        return target;
    }

    /**
     * url 解码
     * @param source
     * @return
     */
    public static String decodeURL(String source){
        String target;
        try {
            target = URLDecoder.decode(source, "utf-8");
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("url解码失败"+e);
            throw new RuntimeException(e);
        }
        return target;
    }
}
